home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Ghost 1.0 / source / Ghost ƒ / Ghost code / ghost files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.1 KB  |  158 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        ghost files.c
  4.  
  5. Purpose:    This module handles standard file dialogs for loading
  6.             and saving games on disk.
  7.  
  8.  
  9. Ghost -=- a classic word-building challenge
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "Script.h"
  30. #include "ghost files.h"
  31. #include "ghost load-save.h"
  32. #include "ghost globals.h"
  33. #include "msg graphics.h"
  34. #include "msg environment.h"
  35.  
  36. Boolean GetSourceFile(FSSpec *gameFile, Boolean useOldGame)
  37. {
  38.     Point                where;
  39.     OSErr                isHuman;
  40.     StandardFileReply    reply;
  41.     SFReply                oldReply;
  42.     unsigned int        count;
  43.     SFTypeList            typeList;
  44.     FInfo                fndrInfo;
  45.     long                procID;
  46.     int                    i;
  47.     
  48.     typeList[0]=SAVE_TYPE;
  49.     isHuman=FALSE;
  50.     if ((gStandardFile58) && (!useOldGame))
  51.         StandardGetFile(0L, 1, typeList, &reply);
  52.     else
  53.     {
  54.         where.h = (gMainScreenBounds.right - 348)/2;
  55.         where.v = (gMainScreenBounds.bottom - 200)/3;
  56.         SFGetFile(where, "\p", 0L, 1, typeList, 0L, &oldReply);
  57.         
  58.         reply.sfGood = oldReply.good;
  59.         if (reply.sfGood)
  60.         {
  61.             reply.sfType = oldReply.fType;
  62.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  63.                                 &reply.sfFile.parID, &procID);
  64.             if (isHuman!=noErr)
  65.             {
  66.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  67.                 reply.sfFile.parID = 0;
  68.             }
  69.             count=oldReply.fName[0];
  70.             for (i=0; i<=count; i++)
  71.                 reply.sfFile.name[i]=oldReply.fName[i];
  72.             
  73.             reply.sfScript=smSystemScript;
  74.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  75.                                 reply.sfFile.name, &fndrInfo);
  76.             reply.sfFlags=(isHuman==noErr) ? fndrInfo.fdFlags : 0;
  77.             
  78.             reply.sfIsFolder=FALSE;
  79.             reply.sfIsVolume=FALSE;
  80.         }
  81.     }
  82.  
  83.     if ((reply.sfGood) && (!isHuman) && (!useOldGame))
  84.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  85.                             gameFile);
  86.         
  87.     return ((reply.sfGood) && (!isHuman));
  88. }
  89.  
  90. Boolean GetDestFile(FSSpec *gameFile, Boolean *deleteTheThing)
  91. {
  92.     unsigned int        count;
  93.     Str255                otherName;
  94.     StandardFileReply    reply;
  95.     SFReply                oldReply;
  96.     Point                where;
  97.     FInfo                fndrInfo;
  98.     long                procID;
  99.     OSErr                isHuman;
  100.     int                    i;
  101.         
  102.     if (gStandardFile58)
  103.         StandardPutFile("\pSave Ghost game as...", "\p", &reply);
  104.     else
  105.     {
  106.         where.h = (gMainScreenBounds.right - 304)/2;
  107.         where.v = (gMainScreenBounds.bottom - 184)/3;
  108.         SFPutFile(where, "\pSave Ghost game as...", "\p", 0, &oldReply);
  109.         reply.sfGood = oldReply.good;
  110.         if (reply.sfGood)
  111.         {
  112.             isHuman=GetWDInfo(oldReply.vRefNum, &reply.sfFile.vRefNum,
  113.                                 &reply.sfFile.parID, &procID);
  114.             if (isHuman!=noErr)
  115.             {
  116.                 reply.sfFile.vRefNum = oldReply.vRefNum;
  117.                 reply.sfFile.parID = 0;
  118.             }            
  119.             count=oldReply.fName[0];
  120.             for (i=0; i<=count; i++)
  121.                 reply.sfFile.name[i]=oldReply.fName[i];
  122.             
  123.             reply.sfScript = smSystemScript;
  124.             isHuman=HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID,
  125.                                 reply.sfFile.name, &fndrInfo);
  126.             reply.sfReplacing=(isHuman!=fnfErr);
  127.             
  128.             reply.sfIsFolder=FALSE;
  129.             reply.sfIsVolume=FALSE;
  130.         }
  131.     }
  132.  
  133.     if (reply.sfGood)
  134.     {
  135.         *deleteTheThing=reply.sfReplacing;    
  136.         MyMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name,
  137.                         gameFile);
  138.     }
  139.     
  140.     return (reply.sfGood);
  141. }
  142.  
  143. pascal OSErr MyMakeFSSpec(short vRefNum, long parID, ConstStr255Param fileName,
  144.     FSSpecPtr myFSS)
  145. {
  146.     int            i;
  147.     
  148.     if (gHasFSSpecs)
  149.         FSMakeFSSpec(vRefNum, parID, fileName, myFSS);
  150.     else
  151.     {
  152.         myFSS->vRefNum=vRefNum;
  153.         myFSS->parID=parID;
  154.         for (i=fileName[0]; i>=0; i--)
  155.             myFSS->name[i]=fileName[i];
  156.     }
  157. }
  158.